<template>
  <div class="box">
    <h3 class="title">
      后台管理系统
    </h3>
    <div class="loginBox">
      <el-form
        ref="system"
        :rules="loginRules"
        :model="system"
        label-width="80px"
        size="small"
        style="margin-top:50px;"
      >
        <el-row>
          <el-col :span="20">
            <el-form-item
              label="账号:"
              prop="number"
            >
              <el-input
                v-model="system.number"
                clearable
                placeholder="请输入账号"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item
              label="密码:"
              prop="password"
            >
              <el-input
                v-model="system.password"
                clearable
                type="password"
                placeholder="请输入密码"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-checkbox
          v-model="system.rememberMe"
          style="margin-left:37px;"
        >
          记住我
        </el-checkbox>
        <div
          class="deng"
          @click="sumbit"
        >登 录</div>
      </el-form>
    </div>
  </div>
</template>
<script>
import Cookies from 'js-cookie'
export default {
  name: 'Login',
  data() {
    return {
      loginRules: {
        number: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
        password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
        // code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
      },
      system: {
        number: 'admin',
        password: 123456,
        rememberMe: false
      }
    }
  },
  created() {
    // this.getCookie()
  },
  methods: {
    getCookie() {
      const username = Cookies.get('username')
      let password = Cookies.get('password')
      const rememberMe = Cookies.get('rememberMe')
      // 保存cookie里面的加密后的密码
      this.cookiePass = password === undefined ? '' : password
      password = password === undefined ? this.loginForm.password : password
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password,
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
        code: ''
      }
    },
    // 登录
    sumbit() {
      this.$refs.system.validate(valid => {
        if (valid) {
          this.$router.push({
            name: 'Main'
          })
        } else {
          this.$message({
            message: '账号密码不能为空',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.box {
  width: 100%;
  height: 100%;
  background-image: url("https://lelyzimags.oss-cn-shenzhen.aliyuncs.com/sp/20220214/16580842903c4d.PNG");
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.loginBox {
  width: 500px;
  height: 300px;
  // border: 2px solid #1f84ef;
  border-radius: 20px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  opacity: 0.8;
}
.deng {
  width: 150px;
  height: 30px;
  background-color: #1f84ef;
  font-size: 20px;
  line-height: 30px;
  text-align: center;
  color: #fff;
  border-radius: 20px;
  margin: 0 auto;
  margin-top: 70px;
  cursor: pointer;
}
.title {
  // text-align: center;
  color: #fff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -800%);
}
</style>